Update to error handling and logging