Moved sorting into Util