Optimizing loops

Optimizing a couple of stray for loops