Refactoring of some parts of bash scripts