Second version, more functional, now lazy