Made previous version of sorting much more beautiful