added some comments; moved events to top.