My conditional logic is not working sometimes