boundary cases addded
original substring code