Refactor whitespace measurement into it's own function.

So it can be fixed.