Added connect and close hooks