Making encode() method