Some refactoring, comments on demo, and removing a sort bottleneck