Major refactoring of PageClassifier backend code