Renamed and rewrite version. Without iterators.