fixed complex gateway test, loopCounter now starts at first entering of a node, code cleanup