Added valid node checking