factory: split factory.py to factory modules; add setup.py; fix a bugs in tests
factory: pass all tests
factory: refactoring
factory: add docstrings to modules