Fixed substr(), but no kidding now.

all the signed/unsigned arithmetic needs clear understanding