vectorized initial implementation