implemented sort() function