changed cost function on State to use heuristic if cost is undefined. some refactoring of Rational