Fixed implicit global var + some cleanup

mocha complained about a leaked global var in my app, and I traced it down to node-treelib.