fix some bugs in this script