Refactoring the mem use function so that it does not allocate memory and is decoupled from the trajectory array.