abstracted generators into a function