Fixed the allocation/reallocation issues