Added test harness, fixed a few bugs thrown up by same.