Updated the code - found one bug, one old dead test case.