generalized cleanup and updating