fix sorted n calc