Bug fix for string-opt2 (copied from Tianyi's branch).