fixed sorting algo for multiple sorting support