adding recursive factor func. porting to python3