Fix script bugs