Many more Mocha tests.
Fixed a couple of minor bugs thrown up by the new tests.