all done except input/output and a bit of tidying up