script.py bug fixes

More bug fixes to the script.py code. Hopefully it doesn't have to
change much more