Some fixes to daemon startup/shutdown