this function has become really large with 4 embedded functions.  time for a class IMO.
it's not you're problem Paul, but it's become a problem for the project.