A bunch of changes.

About to separate out into modules