partial refactor towards more functional style

This is a prelude to more refactoring to enable statistics gathering for
large network simulations. It should also end up less unwieldy for future
changes including Cipher Sets and other spec revisions.