refactored the handleAttack method