Extract sort order as a separate function.
Checkpoint commit. Sorting is starting to work again.
Having most of it working again.
Finishing touch.
Merge branch 'feature/insert-correctly'