started refactoring to allow for efficient encoding