refactored version with joined nodes.