Some logging/error handling improvements