Working version of the script.