vectorized version finally!
all my later work,