More re-org and some minor computing changes.

No new functionality introduced, but work on isolating dependencies
and making the code generally more modular and readable.