Convert to cleaner OOP style.
Some more simplifications and style changes.