vectorized version works, but is slower than register version