Refactor decoder