Fix bug in text encoding method.