fixing syntax errors and missing reg key variable