attempted improvement to error handling