Added more event handling.
Fixed merge conflicts.