Conditional logic is not working