Factor out string scanning into it's own function.