Fix trace function