How about pulling this out as a class and testing it? This class already has a lot of functionality  and hiding this in here is a bit overkill I think.