<% @threads.each do |thread| %>
    <% comments_by_parent = thread.group_by(&:parent_comment_id) %> <% subtree = comments_by_parent[nil] %> <% ancestors = [] %> <% while subtree %> <% if (comment = subtree.shift) %>
  1. <%= render "comments/comment", :comment => comment, :show_story => ancestors.empty? %> <% if (children = comments_by_parent[comment.id]) %> <% ancestors << subtree %> <% subtree = children %>
      <% else %>
        <% end %> <% elsif (subtree = ancestors.pop) %>
    1. <% end %> <% end %>
    <% end %>