added parallel support for sampling