fix condition checking bug