update code and vectorize sampling of Z