fully vectorized version