Simplify / fix whitespace detection algorithm.