improved handling of errors