Tidied up a bit and added some explanatory prose