This function definitely needs some API docs; I don't understand how it's supposed to be used at all.