implement batch function