Refactored code to isolate tracing.