[Bug 94] Rewrite of window management code