encoder/decoder refactor phase 1