Advanced main.py

Look at the last three changes in the change history (I must interrupt here. I'll continue later)