Aggressive code organisation and rename.

Not perfect but moves things to roughly the right buckets in
preparation for a second clean-up phase.