added tests and fixes