extracted connection_handler logic from connection