modified a function to more sanely use a generator