Merging new refactors into Paul's separate window version