Memory consumtion was alleviated by using iterator pattern