Tweaked.
Intermediate working version of profiling script.