New function connection_main, handle_connection modified