Initial implementation of revisions. I'm sure this will need improving but a good start.