add better output and error reporting