Add more tracing and error handling