This is so gross. I don't see a better way, though. I would like to see some documentation about the gross things this is doing, since it was non-obvious on my first read through.