Fix build script and correct window closing