Refactoring bash functions