Optimisation and cleanup