moved epoch sampling to function