Fix logic bug