Fix trace termination bug