Broken, about to refactor.
Added failing test to expose high-bit encoding bug
Major refactor and cleanup.