further structure cleanup and reorg. added shutdown hooks.