Refactored and corrected spam check algorithm.