replace foreach with expand