If you convert the above function to be a generator, you wouldn't need this method.