added validation of exisiting of nodes in recursive call