Implementing A* part 4