Refactoring gui.py