General refactoring, prepred NBayes for vectorization