added regular pings to prevent disconnection by timeout
rearranged things in main loop to make pick_target a local variable