Put the shutdown handler in the right place.