Changed the for...in loops to normal for loop