I think this whole block could be a function with docstring documentation since it has a well defined scope. It could `yield` `terms`, which would be used by the update.