Fully vectorized implementation, no more loops