now shows popup
Refactored a bit

Put all the global vars up top so I could collapse and see all the
functions in their own area below.