Could you set `total` to 1, basically saying we'll always try to get at least one page, instead of setting it to nil? That way the next line can just be `while current < total`.