Fixed a logic bug of after extracting the max gram patterns.