Rewritten joinLinesStartingWithSpace to a functional form, removed mutable local variables.