Fixed some script bugs