Vectorized adv code ver 1