Refactored node generation to node_factory.