fixed memory management issues