Moved sorting into proper function to clean up code
Merge branch 'tweaking-ordering' into develop