add better handling of errors