Fixed previously bad error handling