We should put the code to compute these nodes in assign_values() so that it can be pre-computed once, not in every iteration like now.