node selection and path logic