this function is just really difficult to read.  it's not clear what purpose it serves.