Added function to return the optimal path