Fixed some bugs in scripts