Added code to shutdown metrics cleanly when deactivating. Fixes #46.