Fix bug on sort function.