Fix logic and syntax