changed implementation and added fixed some tests.