Fixing bad error handling