Fix syntax and bugs