implementing for_each