Optimisation suggested by Paul Houx