Updated the hide method to detect whether or not the event is defined