Added a helper method for sorting