Chuffing well done it.  Code is a mess, but meh