Fix rewrite condition infinite loop