Major cleanup and "optimisation"