try to limit the number of passes over collections (not really idiomatic but faster)