Added most of the A* code.