Optimize the code that copies strings