Fixed disconnect event handler and added connecterror handler