sorting functions modified (emre)