rewrite using generators & co