this function smells weird.