Tidy up control flow in trace creation