Added contribution by Rory Graves (mostly reformatting with minor fixes)