This could use some high level comment about what this logic is about. Without context, it's not obvious problem it's solving.