Add decoder and refactor