Is this really the only way to detect whether you're shutting down? If so, factor it into a different method since it's a little hacky.