removing possible memory leaks in collecting the results from collections: set, map, list.
correction of some mistakes for the previous commit.