Moved Profiling class into util module.
Moved top-level code into a function so the file can be used as a module.
Bunch of fixes for the hierarchical dart throwing algorithm.