improve error reporting and handling