Updated with minor changes to trace handling.