added test suite, bug fixes resulting from test