altered cleanup function