Added shutdown hooks to exit