implementing node lookup algorithm - final stage!