It seems like it might be sensible to split these two arms into separate functions (since they're handling two different things), but they probably capture a lot of the environment above? (Too much to make the separation worth it?)