get rid of some duplication in expand()