A little refactoring of shell script code

@benhachey I will only merge this if you don't hate such refactoring of shell scripts... so a thumbs up would be nice!