Fix a bug in text encoding