fix factory fn, add some comments