added the code for path finding