Refactored for using ostream iterators