Optional: I'm not familiar with details of the actual code, but intuition says to me that this block could become a helper function with a descriptive name.