Refactored getting the window object to make it testable. Added more tests.