Optimise function.