Refactoring code in MainFrame