Clean up shutdown handling
Merge pull request #53 from Rosuav/shutdown

Clean up shutdown handling