tried to get the memory allocation and pointers correct for loop over path improvements