Rewrite graph shrinking