Rewrite and add as a static lib.