Very rough first draft at updating. Works, but I'll tidy it as I understand things better