Refactored main.py to enable fanout specification