fixed bug that throws StringIndexOutOfBoundsException