refactored, faster, faster sorting