added exception handling for connect