First attempt (lots of swearing).