More cleanup
Added three-way tree matching