fix leafnode, refine code