fixing tests.  rework on code slightly