Fixed substring/index issues