Some bug fixing in scripts