Why is my conditional logic not working?