Implemented duplicate word detection and handling