added explicit code for handling traceBegin and traceEnd.