Remove trailing spaces.
Some serious refactoring.