added iter as alternative to gather to save memory