tried to optimise the script,