Finishe first untested code.
Added test class.  Fixed some bugs.