Make error handling more robust

Return when error has been detected.