Does some refactoring, adds decode_index64, fixes some TODOs.