Generator function now working