shell code refactoring