refactoring script and adding unit tests.