Moved some memory allocation out of best_knot.