expand_bb function (not exported)