Updated code so that all tests pass.  I changed things I don't understand; I don't claim anything other than that the tests now pass on my machine.