optimization and refactoring Naive Bayes Classifier