fixed cleanup code