Version of Encoder that works and is tested