Changed for loop to a better one