Write shutdown functions.