Fixed wrong index to substring