Changed error checking to exit on error