Improve string partitioning logic.