encoder refactoring