Fixing the danger zone code to make sure the window does not hang off the edge of the screen.