Completed sorting algorythm for find_marks