Adding event handling to connections; some structure simplification