Added profiling and instruemntation.  Fixed a few defects.