Refactored using addEventListener