I know there is more work to be done in this area (i.e. it's not the main focus of the review).  If possible, may be nice to refactor it down in to smaller chunks.