My working (if a little impenetrable) attempt