refactoring some code in the listener, using switch statement, changing method name in main window