added iterations and memory management