fixed substr range; added -o option