fixed bug, vectorized