Vectorized with fixed IF statement