Refactorization of two scripts to enhance the logic between files and modularization.