Cleaned up a bit according to http://mywiki.wooledge.org/BashGuide/Practices