added more tests and a couple bug fixes