Why does not correctly work with the conditions?