Fix a few bugs in scripts