Added initial code, written by Mark Slee and I two yearyears ago