Fix bug in trace handler