Fixed attempts to close connections that might not exist

Rather than nil pointering out