I was slightly uncomfortable making this one large function, but it is well structured inside in a way that would hardly change making it a class, except for added boiler plate. So it seemed ok to me. WDYT?