factored out window code