Untangling generator functions from global variables