finally got the sorting process to work