added tests and did refactoring