Added tests and fixed bugs discovered in testing.
Added more tests