Update for 2.5 and patch logic errors

I was able to productionalize the script and test it out. There were a number of bugs which have been ironed out.