more clean up of mallocs and frees