Primarily cleanup, reworked hacky code in window.js

It's still hacky, though. Eventually I'll replace it with something
better.