Added the boundary condition for path calculation and fixed the ghost movement issue