Sort data in memory; bug fixes

Test Plan:
WIP