Added a second (and hopefully final) version of the script.