gui.R refactoring