Refactored main window code file