refactor decode functions