Control flow issues

Hi Klacke attached pull contains a a number of performance improvements, as well as a few potential bugs.  UT's run fine, I've also tested against our use of confd.