Implemented entire encoding chain, only output processing is missing