fixed script bugs