Fixed syntax and logical error