Fixed bug and made coding part separate from the tree part