added backtracking in dynamic pathfinding