Refactored connection callback.