adding tests, and changes from bug fixes exposed by tests