refactoring the shell scripts to make them more generic and maintenable