sorting re-write