Solved the sort and count problem incorrectly without errors