sampling function updated