Fix bug in nodes and add tests