try to implement using generators