How the script works