fix exitSafely