Somewhat working.
Refactoring.
Refactoring.
Refactoring.
Fix warnings.
More refactoring.