Use wait_until instead of relying on sleep