fixed some bugs in script