switching to foreach