optimize loop. In the slow device like ipad 1 or iphone 4, it runs much faster