improve event handling, various code cleanup

Signed-off-by: William Rockwood <wrockwood@tadl.org>