Why my conditions are not working properly?