restructured constructor; added event handling