added connection events and fixed minor issue with connnection being closed after callback