Refactored encoding