Improved efficiency of script