Restructured the memory allocation code in order to use it to reallocate memory.