Refactor the decoder