Add debuging option and custom event listener