Refactoring script to be more modular.