Some more cleaning and optimisation