Fix bug in encoder