added better error reporting