adding sort method
refactoring sort method