main.py: more bug fixes