 
   defp wrap_expr(current, line, buffer, chars, state) do
     new_lines = List.duplicate(?\n, line - state.line)
-    key = length(state.dict)
+    key = length(state.quoted)
     placeholder = '__EEX__(' ++ integer_to_list(key) ++ ');'
-    {current ++ placeholder ++ new_lines ++ chars, state.update_dict(&[{key, buffer}|&1])}
+    {current ++ placeholder ++ new_lines ++ chars,
+     %{state | quoted: [{key, buffer}|state.quoted]}}
   end
 
   # Look text ahead on expressions


  # Changes placeholder to real expression

  defp insert_quotes({:__EEX__, _, [key]}, dict) do
    {^key, value} = List.keyfind dict, key, 0
    value
  end

  defp insert_quotes({left, line, right}, dict) do
    {insert_quotes(left, dict), line, insert_quotes(right, dict)}
  end

  defp insert_quotes({left, right}, dict) do
    {insert_quotes(left, dict), insert_quotes(right, dict)}
  end

  defp insert_quotes(list, dict) when is_list(list) do
    Enum.map list, &insert_quotes(&1, dict)
  end

  defp insert_quotes(other, _dict) do
    other
  end
end


  defp generate_buffer([{:start_expr, start_line, mark, chars}|t], buffer, scope, state) do
    {contents, line, t} = look_ahead_text(t, start_line, chars)
    {contents, t} = generate_buffer(t, "", [contents|scope],
                                    %{state | quoted: [], line: line, start_line: start_line})
    buffer = state.engine.handle_expr(buffer, mark, contents)
    generate_buffer(t, buffer, scope, state)
  end

  defp generate_buffer([{:middle_expr, line, _, chars}|t], buffer, [current|scope], state) do
    {wrapped, state} = wrap_expr(current, line, buffer, chars, state)
    generate_buffer(t, "", [wrapped|scope], %{state | line: line})
  end

  defp generate_buffer([{:end_expr, line, _, chars}|t], buffer, [current|_], state) do
    {wrapped, state} = wrap_expr(current, line, buffer, chars, state)
    tuples = Code.string_to_quoted!(wrapped, [line: state.start_line, file: state.file])
    buffer = insert_quoted(tuples, state.quoted)
    {buffer, t}
  end

