Implemented cleanup routines.