Fix logic problem