function [] = Backtrack(app,pathout)
%% Backward Pathfinding
Targets = app.Targets;
app.targets = app.Targets;
% Create the new pathin
pathin2.p = repmat(pathout.p(1,1:2),size(Targets,1)*2,1);
pathin2.mag = app.pathin.mag;
pathpts = nan(length(pathout.C),2*size(app.targets,1));
for i = 1 : size(Targets,1)
    figure(2)
    hold on;
    plot(app.pathin.p(1),app.pathin.p(2),'ok','markerfacecolor','k','markersize',12)
    tmppath.C = pathout.C(1:pathout.crosscount(i));
    tmppath.p = pathout.p(1:pathout.crosscount(i),:);
    tmppath.t = pathout.t(1:pathout.crosscount(i));
    tmppath.v = pathout.v(1:pathout.crosscount(i));
    tmppath.c = pathout.c(1:pathout.crosscount(i));
    tmppath.mag = pathout.mag;
    tmp = findpath(tmppath,Targets(i,:),10);
    pathpts(1:size(tmp.P,1),2*i-1:2*i) = tmp.P;
end
for i = size(Targets,1) + 1: size(Targets,1) * 2
    heading = Targets(i - size(Targets,1),:) - pathout.p(1,1:2);
end