Some tidying up but worryingly there is a an unused variable which
looks like it might be important.