Fix logic order