optimizing loops

Optimizing a couple of stray for loops