clean up and optimise the scripts