def flatten_comments(comments, root_level=0):
        stack = comments[:]
        for item in stack:
            item.nested_level = root_level
        retval, parent_candidates = [], {}
        while stack:
            item = stack.pop(0)
            if isinstance(item, praw.objects.MoreComments) and item.count == 0:
                continue
            if item.parent_id:
                parent = parent_candidates.get(item.parent_id[3:])
                if parent:
                    item.nested_level = parent.nested_level + 1
            if hasattr(item, 'replies'):
                for n in item.replies:
                    n.nested_level = item.nested_level + 1
                stack[0:0] = item.replies
            parent_candidates[item.id] = item
            retval.append(item)
        return retval