window close() and various fixes