sorting done properly