Partially implemented event handling algorithm.  Minor modifications.