Please extract this into a function and use this existing comment as the docstring for it.