Made less verbose, fixed bug with using the wrong var in nested for loop.