working on encode functionality