Lots of script optimalisations