add some comments
improve debug traces

- Move trace machinery in new file.

- Change trace level for trace bit mask to allow selective tracing.