Major cleanup 2014 Jan 21

Separated shutthatdown into a module with separate files; cleaned up
code