some refactoring to clean up loading function for MNIST data