final version of script with fixed variable names