Refactoring. keeping encoder and decoder