Clean up trace output and moved around definitions