index checking and rewriting