Fix bug in 'encode