Added MNIST test and fixed some bugs