restructure handling of expand