TEST: vectorized the for loops