refactor app.py
switch status handling
fixes