Add shutdown callback and install it into shutdown hook.

Fixes #5, assuming it works.