Code cleanup.
Massive refactoring.