Changed the for loops to use enumerate function