Fix potential fatal error when the index is not set