avoid linux crashes by stopping before closing, checking more things