modified heuristic code to allow different heuristic functions