Fix syntax and scripting errors