Refactored main window constructor