Replaces a clusterfuck of code with a for loop. Magic\!