Added missing stopPropagation() calls
Improved error message
Improved code