corrected some bugs
Script version 1