A number of changes, largely for code cleanup.

There still seem to be some issues getting things to run properly,
but it is improving.