Refactored actionPerformed() method