Added function 'encode'