Refactoring encoder and calling it explicitly