Added checks on recorded position to ensure window remains on screen