Changed logic to astar