If statement evaluating to False even though logically it should be True