Improvement: Using the canvas rather than the window to determine max positions.