Completely rewrote the existing topic detection logic to be more robust.