optimize loop process