add better error handling and reporting