added adaptive sampling code