Did major refactoring andd added tests