Shell script restructuring