Fix a bug in encoder