refactoring of the bash scripts, change some functions for easy testing