Added more tests and fixed bugs discovered during testing.