Repurposing of Chelsea's fitting script. Should have the same functionality at this point
I think this retains the old functionality still. Somewhat tested. Writes tree