the writing part for Importance Sampling