Working batch function