updated tests and refactoring