Move factory to its own mod and add some lib doc.