fixed pointer issue and segmentation faults that were generated in mem_alloc