Why is my IF statement ignoring my conditional?