changed order of cleanup