Added more tests, and fixed problems thus revealed.