Simplify implementation of substring()

Simplify implementation of substring()

Edit