Fixed string indexing bug