moved sort functions to util