add helper functions for sorting the result list