Refactoring.
Popup now attempts to remain within the visible part of the screen.