Implement optimisation suggested by @kaniini