refactoring, structured window saving code