schema BUGFIX several tests and bugfixes of lys_getnext()
diff --git a/src/tree_schema.c b/src/tree_schema.c
index 21fc337..cabccb2 100644
--- a/src/tree_schema.c
+++ b/src/tree_schema.c
@@ -53,7 +53,7 @@
                 next = last = (const struct lysc_node*)&((struct lysc_node_choice*)parent)->cases[0];
             } else {
                 snode = lysc_node_children_p(parent, (options & LYS_GETNEXT_OUTPUT) ? LYS_CONFIG_R : LYS_CONFIG_W);
-                /* do not return anything if the augment does not have any children */
+                /* do not return anything if the node does not have any children */
                 if (!snode || !(*snode)) {
                     return NULL;
                 }
@@ -66,15 +66,12 @@
         if (!next) {
             /* try to get action or notification */
             goto repeat;
-        } else if (!(options & LYS_GETNEXT_NOSTATECHECK)) {
-            if (!lys_is_disabled(next, 0)) {
-                return next;
-            }
-            /* continue to find next available node */
-        } else {
-            return next;
         }
+        /* test if the next can be returned */
+        goto check;
+
     } else if (last->nodetype == LYS_ACTION) {
+        action_flag = 1;
         if (last->parent) {
             actions = lysc_node_actions(last->parent);
         } else {
@@ -90,6 +87,7 @@
         }
         goto repeat;
     } else if (last->nodetype == LYS_NOTIF) {
+        action_flag = notif_flag = 1;
         if (last->parent) {
             notifs = lysc_node_notifs(last->parent);
         } else {
@@ -115,7 +113,7 @@
     }
     if (!next) {
         /* possibly go back to parent */
-        if (last->parent != parent) {
+        if (last && last->parent != parent) {
             last = last->parent;
             next = last->next;
         } else if (!action_flag) {
@@ -129,6 +127,7 @@
         }
         goto repeat;
     }
+check:
     switch (next->nodetype) {
     case LYS_ACTION:
     case LYS_NOTIF:
@@ -158,7 +157,7 @@
         } else {
             /* go into */
             if (options & LYS_GETNEXT_WITHCASE) {
-                next = (struct lysc_node*)&((struct lysc_node_choice *)next)->cases;
+                next = (struct lysc_node*)((struct lysc_node_choice *)next)->cases;
             } else {
                 next = ((struct lysc_node_choice *)next)->cases->child;
             }