Added a basic sorting function but I want it to be less crufty