yet more refactoring of shell scripts