Fixed up gradient checking
Refactoring, added test of MNIST