You are modifying a `var` inside a `map` application. Remember `map` should not have side-effects.

I suggest you separate out the check for sourceNames into a separate function and use `foreach` whenever you need a side-effect.