basic substring (single string on a leaf)
improved substr, converted more duplicated code into functions