Eliminate duplication for _get_remaining_item_count function