Fix StringIndexOutOfBoundsException