Cleaning up code.

Cleaning up code.  Reimplementing features that were slow or poorly written.