refactor and spin in main window