improve string generation logic.