I think this needs more explanation, it's very unclear what this function is doing.