Some minor refactoring, and whitespace fixes