fixed some memory allocation issues