faster nearest node algorithm