using a foreach instead of mapPartitions