factory.py: refactoring of in_loop()