A better optimisation, as suggested by TomH.