Slight tweak to avoid duplicate calls to indexOf: bail out of if check sooner.