Moved some code back into the window from modules since it seems to use
less memory.