Fix syntax errors and missing variables