This is an near-final version of the script