20140923 implemented templated tree. Debug needed.