bug fix and initial unit tests pass