Bugfixing shutdown hook. but its still throwing exceptions.