Error fixed for batch sampling