fix logic order