Must set visited to true at same time as cost is set. Fixes bug.