Some optimizations in the detection of phrases and words.
Added BOM detection.