Refactor mini-batch gradient.
More refactoring.
Remove duplicate code.
Remove duplicate code.
Simplify error function.