xup: no logic change, seperate one big function out