another super long function. breaking it up into readable logical chunks would be more maintainable. it doesn't look like the gcsg says anything specific. @rwcarlsen, what are your thoughts?