change retry loop to test before decrementing