Build in a safe way to close windows without exit the program.