added some missing calls to build_tree(), fixed a bug in func(), and
added some comments