Abstract window management code

In preparation of having multiple windows.

Also remove analytics code that snuck in