Fix bugs with events. Update sample.