code improve for safety of string operation.