diff --git a/simplecpreprocessor.py b/simplecpreprocessor.py
index d6d025b..53da5fb 100644
--- a/simplecpreprocessor.py
+++ b/simplecpreprocessor.py
@@ -104,6 +104,7 @@ IFDEF = "ifdef"
 IFNDEF = "ifndef"
 ELSE = "else"
 SKIP_FILE = object()
+TOKEN = re.compile(r"\b\w+\b")
 
 
 class Preprocessor(object):
@@ -228,27 +229,22 @@ class Preprocessor(object):
             self.process_define(define, old_line_num)
 
     def process_source_line(self, line, line_num):
-        matches = set()
-        line = self._recursive_transform(line, matches)
+        line = self._recursive_transform(line, set())
         return line + self.line_ending
 
-    def _recursive_transform(self, line, matches):
-        original_line = line
-        new_matches = set()
+    def _recursive_transform(self, line, seen):
 
         def transform_word(match):
             word = match.group(0)
-            if word in matches:
+            if word in seen:
                 return word
             else:
-                new_matches.add(word)
-                return self.defines.get(word, word)
-        line = re.sub(r"\b\w+\b", transform_word, line)
-        matches.update(new_matches)
-        if original_line == line:
-            return line
-        else:
-            return self._recursive_transform(line, matches)
+                local_seen = {word}
+                local_seen.update(seen)
+                word = self.defines.get(word, word)
+                return self._recursive_transform(word, local_seen)
+
+        return TOKEN.sub(transform_word, line)
 
     def skip_file(self, name):
         item = self.include_once.get(name)

diff --git a/test_simplecpreprocessor.py b/test_simplecpreprocessor.py
index 71ae36d..8a4f33b 100644
--- a/test_simplecpreprocessor.py
+++ b/test_simplecpreprocessor.py
@@ -97,6 +97,14 @@ class TestSimpleCPreprocessor(ProfilerMixin, unittest.TestCase):
         expected_list = ["(4 + (2 * x))\n", "(2 * (4 + y))\n"]
         self.run_case(f_obj, expected_list)
 
+    def test_define_indirect_self_reference_multiple(self):
+        f_obj = FakeFile("header.h", ["#define I 1\n",
+                                      "#define J I + 2\n",
+                                      "#define K I + J\n",
+                                      "I\n", "J\n", "K\n"])
+        expected_list = ["1\n", "1 + 2\n", "1 + 1 + 2\n"]
+        self.run_case(f_obj, expected_list)
+
     def test_partial_match(self):
         f_obj = FakeFile("header.h", [
             "#define FOO\n",

Macro expansion produces produces wrong results
See for details https://github.com/nanonyme/simplecpreprocessor/commit/c3a1d4617fa0977bbc0f6bd0098b2d74219489bf
test_simplecpreprocessor.py::TestSimpleCPreprocessor::test_define_indirect_self_reference_multiple
test_simplecpreprocessor.py::TestSimpleCPreprocessor::test_blank_define test_simplecpreprocessor.py::TestSimpleCPreprocessor::test_complex_ignore test_simplecpreprocessor.py::TestSimpleCPreprocessor::test_define test_simplecpreprocessor.py::TestSimpleCPreprocessor::test_define_indirect_self_reference test_simplecpreprocessor.py::TestSimpleCPreprocessor::test_define_inside_ifndef test_simplecpreprocessor.py::TestSimpleCPreprocessor::test_define_parens test_simplecpreprocessor.py::TestSimpleCPreprocessor::test_define_simple_self_referential test_simplecpreprocessor.py::TestSimpleCPreprocessor::test_define_undefine test_simplecpreprocessor.py::TestSimpleCPreprocessor::test_define_with_comment test_simplecpreprocessor.py::TestSimpleCPreprocessor::test_expand_size_t test_simplecpreprocessor.py::TestSimpleCPreprocessor::test_extra_endif_causes_error test_simplecpreprocessor.py::TestSimpleCPreprocessor::test_fulfilled_ifdef_define_allowed test_simplecpreprocessor.py::TestSimpleCPreprocessor::test_fullfile_guard_ifdef_noskip test_simplecpreprocessor.py::TestSimpleCPreprocessor::test_fullfile_guard_ifdef_skip test_simplecpreprocessor.py::TestSimpleCPreprocessor::test_fullfile_guard_ifndef_noskip test_simplecpreprocessor.py::TestSimpleCPreprocessor::test_fullfile_guard_ifndef_skip test_simplecpreprocessor.py::TestSimpleCPreprocessor::test_handler_existing_file test_simplecpreprocessor.py::TestSimpleCPreprocessor::test_handler_missing_file test_simplecpreprocessor.py::TestSimpleCPreprocessor::test_ifdef_else_defined test_simplecpreprocessor.py::TestSimpleCPreprocessor::test_ifdef_else_undefined test_simplecpreprocessor.py::TestSimpleCPreprocessor::test_ifdef_file_guard test_simplecpreprocessor.py::TestSimpleCPreprocessor::test_ifdef_left_open_causes_error test_simplecpreprocessor.py::TestSimpleCPreprocessor::test_ifdef_unfulfilled_define_ignored test_simplecpreprocessor.py::TestSimpleCPreprocessor::test_ifdef_with_comment test_simplecpreprocessor.py::TestSimpleCPreprocessor::test_ifndef_else_defined test_simplecpreprocessor.py::TestSimpleCPreprocessor::test_ifndef_else_undefined test_simplecpreprocessor.py::TestSimpleCPreprocessor::test_ifndef_fulfilled_define_allowed test_simplecpreprocessor.py::TestSimpleCPreprocessor::test_ifndef_left_open_causes_error test_simplecpreprocessor.py::TestSimpleCPreprocessor::test_ifndef_unfulfilled_define_ignored test_simplecpreprocessor.py::TestSimpleCPreprocessor::test_ignore_include_path test_simplecpreprocessor.py::TestSimpleCPreprocessor::test_include_local_file_with_subdirectory test_simplecpreprocessor.py::TestSimpleCPreprocessor::test_include_missing_local_file test_simplecpreprocessor.py::TestSimpleCPreprocessor::test_include_with_path_list test_simplecpreprocessor.py::TestSimpleCPreprocessor::test_include_with_path_list_with_subdirectory test_simplecpreprocessor.py::TestSimpleCPreprocessor::test_lines_normalize_custom test_simplecpreprocessor.py::TestSimpleCPreprocessor::test_lines_normalized test_simplecpreprocessor.py::TestSimpleCPreprocessor::test_multiline_define test_simplecpreprocessor.py::TestSimpleCPreprocessor::test_no_fullfile_guard_ifdef test_simplecpreprocessor.py::TestSimpleCPreprocessor::test_no_fullfile_guard_ifndef test_simplecpreprocessor.py::TestSimpleCPreprocessor::test_partial_match test_simplecpreprocessor.py::TestSimpleCPreprocessor::test_platform_constants test_simplecpreprocessor.py::TestSimpleCPreprocessor::test_pragma_once test_simplecpreprocessor.py::TestSimpleCPreprocessor::test_repeated_macro test_simplecpreprocessor.py::TestSimpleCPreprocessor::test_space_macro_indentation test_simplecpreprocessor.py::TestSimpleCPreprocessor::test_tab_macro_indentation test_simplecpreprocessor.py::TestSimpleCPreprocessor::test_unexpected_macro_gives_parse_error