Refactored trace printing code a bit.