Vectorized NW with some optimization