Code cleanup.  Removed some debugging stuff.  Mild refactoring for readability.  Doc comments added.