Added on_hide and improved event attach/detaching