checked corner cases for substring