add mathew + fix minibatch extraction to handle uneven numbers