Refactor to introduce Window class.