rewrite some code in libs