make minibatch function flexible