nfactory's code