Added error-handling for possible connection failures.