Recursive sorting to enable multiple sort functions to operate