Refactor mini-batch gradient.
More refactoring.
Remove duplicate code.