A lot of refactoring.
Work in progress.