Fixed error in corrupt layout if program closes unexceptedly