Improves regexp algorithm