fixed string index out of bounds error