added check for connection before setting up listeners