refactored ping_loop