added tests and accompanying fixes