Major re-org of the code.