Refactoring for handwritten digits