Improved handling of errors