lots of updates

all various updates made while trying to split off tasks found in the
loop to logical functions which can be called.  This is all for the
purposes of adapting the code to be able to perform unit testing.