Added connection and disconnection callbacks
code cleanup