improved function which determines if statement is the last in path
fixed bug in detecting last node in path
enabled copying node_state by value