Added a check on the key before trying to connect