fixed memory alloc issues