Add clean shutdown mechanism.