Optimized the function of fill_connection_key.