I realize this is a very hairy bit of code, but I don't quite follow this comment...