Minor optimization to sorting