Implemented sort method.