Refactored decode logic. Added initial encode logic.