added tests
fixed implementation