Fix logic issues