refactoring decoderstate and splitting things into modules