refactoring bash script