Just wrote it all in one go. Compiles but remains untested