Added better checks for screen bounds.