indexed for loops to reduce memory allocation, cleanup