diff --git a/algograph/lexer.py b/algograph/lexer.py
index 9d0e50f..39fa603 100644
--- a/algograph/lexer.py
+++ b/algograph/lexer.py
@@ -64,10 +64,10 @@ class Lexer:
         old, self.indent = self.indent, indent
 
         if indent > old:
-            yield INDENT(indent)
+            yield INDENT(indent - old)
 
         elif indent < old:
-            yield DEDENT(indent)
+            yield DEDENT(old - indent)
 
     def ignore(self, value):
         return []
diff --git a/algograph/parser.py b/algograph/parser.py
index c1b0840..cb4f890 100644
--- a/algograph/parser.py
+++ b/algograph/parser.py
@@ -85,9 +85,12 @@ def reduce_by_rule(rule):
 
 
 class Parser:
-    def __init__(self, algorithm):
+    def __init__(self, algorithm=None, tokens=None):
         self.algorithm = algorithm
-        self.tokens = Lexer(algorithm).tokenize()
+        if algorithm is None:
+            self.tokens = tokens
+        else:
+            self.tokens = Lexer(algorithm).tokenize()
 
     def reduce(self):
         '''
@@ -164,7 +167,12 @@ class Parser:
             raise SyntaxError
 
         token = SUITE(*stack[-i + 1: -1])
+        dedent = stack[-1].value
+        indent = stack[-i].value
         stack[-i:] = [token]
+        if dedent > indent:
+            stack.append(DEDENT(dedent - indent))
+            self._SUITE()
 
     @reduce_by_rule
     def _IFSWITCH(self):
@@ -213,7 +221,8 @@ class Parser:
             last = node
 
             not_ = stack[2].EXPR.NOT
-            yes = N(stack[2].SUITE.tokens[0].ID.value)
+            ## yes = N(stack[2].SUITE.tokens[0].ID.value)
+            yes = Parser(None, stack[2].SUITE.tokens).parse().root
             node[yes] = not not_
 
             elif_ = stack[2].ELIF
@@ -222,13 +231,15 @@ class Parser:
                     not_ = o.NOT
                     o = N(o.ID.value)
                     node[o] = not_
-                    s = N(s.tokens[0].ID.value)
+                    ## s = N(s.tokens[0].ID.value)
+                    s = Parser(None, s.tokens).parse().root
                     o[s] = not not_
                     node = o
 
             no = stack[2].ELSE
             if no:
-                no = N(no.tokens[0].ID.value)
+                ## no = N(no.tokens[0].ID.value)
+                no = Parser(None, no.tokens).parse().root
                 node[no] = not_
 
             del stack[2]

Complex branches (more then one statement) not working
diff --git a/test/test_lexer.py b/test/test_lexer.py
index 99b4552..e04c4e9 100644
--- a/test/test_lexer.py
+++ b/test/test_lexer.py
@@ -47,7 +47,7 @@ class TestLexer:
                 INDENT(2),
                 ID('y'),
                 NEWLINE(),
-                DEDENT(0),
+                DEDENT(2),
                 ID('end'),
                 NEWLINE()
         ]
@@ -71,7 +71,7 @@ class TestLexer:
                 INDENT(2),
                 ID('one'),
                 NEWLINE(),
-                DEDENT(0),
+                DEDENT(2),
                 ELIF(),
                 ID('q'),
                 IS(),
@@ -82,14 +82,14 @@ class TestLexer:
                 INDENT(2),
                 ID('two'),
                 NEWLINE(),
-                DEDENT(0),
+                DEDENT(2),
                 ELSE(),
                 LITERAL(':'),
                 NEWLINE(),
                 INDENT(2),
                 ID('three'),
                 NEWLINE(),
-                DEDENT(0),
+                DEDENT(2),
                 ID('end'),
                 NEWLINE()
         ]
diff --git a/test/test_parser.py b/test/test_parser.py
index 8f62515..b9a72fa 100644
--- a/test/test_parser.py
+++ b/test/test_parser.py
@@ -29,6 +29,21 @@ class TestParser:
                      |   y
                      ''') == G(N('q', {N('y'): True}))
 
+    def test_multistatemnt_suite(self):
+        assert parse('''
+                     | if q:
+                     |   first
+                     |   second
+                     ''') == G(N('q', {N('first', {N('second'): None}): True}))
+
+    def test_multilevel_suite(self):
+        assert parse('''
+                     | if q:
+                     |   if q2:
+                     |     first
+                     |     second
+                     ''') == G(N('q', {N('q2', {N('first', {N('second'): None}): True}): True}))
+
     def test_if_not(self):
         assert parse('''
                      | if not q:

pip install -e .[dev]
parse_log_pytest
pytest pytest-cov codecov
3.9
pytest --no-header -rA --tb=line --color=no -p no:cacheprovider -W ignore::DeprecationWarning
-e git+https://github.com/genadijrazdorov/algograph.git@967e516a99fba43b6ce4cd4991e547739b86eef9#egg=algograph
build==1.2.2.post1
certifi==2025.1.31
charset-normalizer==3.4.1
check-manifest==0.50
codecov==2.1.13
coverage==7.8.0
exceptiongroup==1.2.2
idna==3.10
importlib_metadata==8.6.1
iniconfig==2.1.0
packaging==24.2
pluggy==1.5.0
pyproject_hooks==1.2.0
pytest==8.3.5
pytest-cov==6.0.0
requests==2.32.3
tomli==2.2.1
urllib3==2.3.0
zipp==3.21.0

name: algograph
channels:
  - defaults
  - https://repo.anaconda.com/pkgs/main
  - https://repo.anaconda.com/pkgs/r
  - conda-forge
dependencies:
  - _libgcc_mutex=0.1=main
  - _openmp_mutex=5.1=1_gnu
  - ca-certificates=2025.2.25=h06a4308_0
  - ld_impl_linux-64=2.40=h12ee557_0
  - libffi=3.4.4=h6a678d5_1
  - libgcc-ng=11.2.0=h1234567_1
  - libgomp=11.2.0=h1234567_1
  - libstdcxx-ng=11.2.0=h1234567_1
  - ncurses=6.4=h6a678d5_0
  - openssl=3.0.16=h5eee18b_0
  - pip=25.0=py39h06a4308_0
  - python=3.9.21=he870216_1
  - readline=8.2=h5eee18b_0
  - setuptools=75.8.0=py39h06a4308_0
  - sqlite=3.45.3=h5eee18b_0
  - tk=8.6.14=h39e8969_0
  - tzdata=2025a=h04d1e81_0
  - wheel=0.45.1=py39h06a4308_0
  - xz=5.6.4=h5eee18b_1
  - zlib=1.2.13=h5eee18b_1
  - pip:
      - build==1.2.2.post1
      - certifi==2025.1.31
      - charset-normalizer==3.4.1
      - check-manifest==0.50
      - codecov==2.1.13
      - coverage==7.8.0
      - exceptiongroup==1.2.2
      - idna==3.10
      - importlib-metadata==8.6.1
      - iniconfig==2.1.0
      - packaging==24.2
      - pluggy==1.5.0
      - pyproject-hooks==1.2.0
      - pytest==8.3.5
      - pytest-cov==6.0.0
      - requests==2.32.3
      - tomli==2.2.1
      - urllib3==2.3.0
      - zipp==3.21.0
prefix: /opt/conda/envs/algograph

test/test_lexer.py::TestLexer::test_indent_dedent test/test_lexer.py::TestLexer::test_keywords test/test_parser.py::TestParser::test_multistatemnt_suite test/test_parser.py::TestParser::test_multilevel_suite
test/test_lexer.py::TestLexer::test_start_end test/test_lexer.py::TestLexer::test_unknown_token test/test_lexer.py::TestLexer::test_newline test/test_parser.py::TestParser::test_start_end test/test_parser.py::TestParser::test_if test/test_parser.py::TestParser::test_if_not test/test_parser.py::TestParser::test_suite_error test/test_parser.py::TestParser::test_if_error test/test_parser.py::TestParser::test_if_else test/test_parser.py::TestParser::test_if_elif_elif_else test/test_parser.py::TestParser::test_if_is
algograph/parser.py algograph/lexer.py
algograph/parser.py algograph/lexer.py