Added stopPropagation() function to avoid unnecessary event listening.