Updated master.py to include mode switching