Refactoring of GUI script