First attempt.  Implementation needs some tidying.