Fixed cleanup on shutdown
Factored classes out into separate modules