Snippets of code taken from my blog at http://codegrunt.co.uk