Fixes to this script after not having used it in years.