TODO: rebuild indexes removes syntactically incorrect references