Condition statements not (always) working