Rewriting to library form