added tests and fixed