more efficent for loop; caching length
'