Solved bug in the function sort.