remove some unwanted spaces.
more refactoring to reduce complexity.