implemented cleanup routines