Added some code for connection checking.