Fix bugs in scripts