vectorized implementation