choose batch size automatically
rafactor, address comments