some refactoring changes and adding tests