Also, if you have many strings, you may want to have a look at this thing (I'm not sure how close to your problem it is):