improve looping efficiency