Improve ping_until function