extract lib and major rewrite