refactoring of bash scipts