Fixed ajax for loop redundancy