Improve interfaces to substring functions, and fix bugs.

11 files changed