cache targets.length outside of the loop