modify sampling loop logic