WIP on NLPCRAFT-385.
diff --git a/nlpcraft/src/main/scala/org/apache/nlpcraft/model/intent/compiler/NCIdlCompilerBase.scala b/nlpcraft/src/main/scala/org/apache/nlpcraft/model/intent/compiler/NCIdlCompilerBase.scala
index 888bcdc..010de1a 100644
--- a/nlpcraft/src/main/scala/org/apache/nlpcraft/model/intent/compiler/NCIdlCompilerBase.scala
+++ b/nlpcraft/src/main/scala/org/apache/nlpcraft/model/intent/compiler/NCIdlCompilerBase.scala
@@ -526,10 +526,10 @@
 
         val fun = id.getText
 
-        def ensureStack(min: Int): Unit = if (stack.size < min) throw rtMissingParamError(min, fun)
         def popMarker(argNum: Int): Unit = if (pop1() != stack.PLIST_MARKER) throw rtTooManyParamsError(argNum, fun)
         def arg[X](argNum: Int, f: () => X): X = {
-            ensureStack(argNum + 1) // +1 for the frame marker.
+            if (stack.size < argNum + 1) // +1 for stack frame marker.
+                throw rtMissingParamError(argNum, fun)
 
             val x = f()
 
@@ -1074,26 +1074,22 @@
         }
 
         def doIsBefore(f: (NCToken, String) => Boolean): Unit = {
-            val (x1, x2) = arg2()
+            val x = arg1()
 
             stack.push(() => {
-                val (t, a, n) = extract2(x1, x2)
+                val Z(arg, n) = x()
 
-                val tok = toToken(t)
-
-                Z(idlCtx.toks.exists(t => t.getIndex > tok.getIndex && f(t, toStr(a))), n)
+                Z(idlCtx.toks.exists(t => t.getIndex > tok.getIndex && f(t, toStr(arg))), n)
             })
         }
 
         def doIsAfter(f: (NCToken, String) => Boolean): Unit = {
-            val (x1, x2) = arg2()
+            val x = arg1()
 
             stack.push(() => {
-                val (t, a, n) = extract2(x1, x2)
+                val Z(arg, n) = x()
 
-                val tok = toToken(t)
-
-                Z(idlCtx.toks.exists(t => t.getIndex < tok.getIndex && f(t, toStr(a))), n)
+                Z(idlCtx.toks.exists(t => t.getIndex < tok.getIndex && f(t, toStr(arg))), n)
             })
         }
 
diff --git a/nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/compiler/functions/NCIdlFunctionsToken.scala b/nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/compiler/functions/NCIdlFunctionsToken.scala
index 347f63a..4e768f9 100644
--- a/nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/compiler/functions/NCIdlFunctionsToken.scala
+++ b/nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/compiler/functions/NCIdlFunctionsToken.scala
@@ -45,7 +45,7 @@
     private def mkMeta(truth: String):TestDesc = TestDesc(truth = truth, token = mkToken(meta = meta))
 
     @Test
-    def test(): Unit =
+    def testMainTokenProperties(): Unit =
         test(
             TestDesc(
                 truth = "tok_id() == 'a'",
@@ -57,7 +57,7 @@
             mkMeta(truth = s"tok_sparsity() == ${meta("nlpcraft:nlp:sparsity")}"),
             mkMeta(truth = s"tok_unid() == '${meta("nlpcraft:nlp:unid")}'"),
             TestDesc(
-                truth = s"tok_is_abstract() == true",
+                truth = s"tok_is_abstract()",
                 token = mkToken(`abstract` = true)
             ),
             mkMeta(truth = s"tok_is_abstract() == false"),
@@ -70,11 +70,11 @@
             mkMeta(truth = s"tok_is_stopword() == ${meta("nlpcraft:nlp:stopword")}"),
             mkMeta(truth = s"tok_is_swear() == ${meta("nlpcraft:nlp:swear")}"),
             TestDesc(
-                truth = s"tok_is_user() == true",
+                truth = s"tok_is_user()",
                 token = mkToken(id = "aa")
             ),
             TestDesc(
-                truth = s"tok_is_user() == false",
+                truth = s"!tok_is_user()",
                 token = mkToken(id = "nlpcraft:nlp")
             ),
             mkMeta(truth = s"tok_is_wordnet() == ${meta("nlpcraft:nlp:dict")}"),
@@ -110,22 +110,56 @@
         )
 
     @Test
-    def testTokenOrder(): Unit = {
+    def testTokenFirstLast(): Unit = {
         val tok = mkToken(id = "a")
 
         tok.getMetadata.put("nlpcraft:nlp:index", 0)
 
         test(
             TestDesc(
-                truth = "tok_is_first() == true",
+                truth = "tok_is_first()",
                 token = tok,
                 idlCtx = mkIdlContext(toks = Seq(tok))
             ),
             TestDesc(
-                truth = "tok_is_last() == true",
+                truth = "tok_is_last()",
                 token = tok,
                 idlCtx = mkIdlContext(toks = Seq(tok))
             )
         )
     }
+
+    @Test
+    def testTokenBeforeId(): Unit = {
+        val tok1 = mkToken(id = "1")
+        val tok2 = mkToken(id = "2")
+
+        tok1.getMetadata.put("nlpcraft:nlp:index", 0)
+        tok2.getMetadata.put("nlpcraft:nlp:index", 1)
+
+        test(
+            TestDesc(
+                truth = "tok_is_before_id('2')",
+                token = tok1,
+                idlCtx = mkIdlContext(Seq(tok1, tok2))
+            )
+        )
+    }
+
+    @Test
+    def testTokenAfterId(): Unit = {
+        val tok1 = mkToken(id = "1")
+        val tok2 = mkToken(id = "2")
+
+        tok1.getMetadata.put("nlpcraft:nlp:index", 0)
+        tok2.getMetadata.put("nlpcraft:nlp:index", 1)
+
+        test(
+            TestDesc(
+                truth = "tok_is_after_id('1')",
+                token = tok2,
+                idlCtx = mkIdlContext(Seq(tok1, tok2))
+            )
+        )
+    }
 }