Optimise some code