Added encoder function