made use of collect rather than each