Refactorization of GUI listener