Patched callback logic and modified connection handling order.