fixed a few bugs.  Preliminary tests work.