preparing extra runtime for replacing recursion with stack based loop