starting to copy some of the profiler code