Clean up and rework profiling code.