fix calculation and make generator to walk nodes