Fixed syntax and scope errors