Bash script actually works now, minor tidy up of template