-functionifying the looping