Add generate neighbor function