Made the code use loops instead of 10x new/