made sort simpler and added sort comparator