fix condition logic