refactor decode