faster isvalid(SubString,i) same patch but cleaner pull