added tests and fix