Have done a bunch of small fixes, hopefully fix #94 but not entirely sure.
Fix last commit which was bad and also fixes #96 sorting.