Fixed tree builder to work for named, unnamed, and partially named trees