modify order of if check to avoid string comparising when not needed