cleanup of shutdown code