part 1 of bug fix and unit tests
basic tests pass. yahoo.