Reduce mapCorners from O(n^2) to O(n)