implemented sort method