Bug fix on substring