I *really* like how you have re-factored this complex method out into its own file and made the conceptual divisions explicit in the code!