Almost finished, only needs the output portion and adding things to the
tree. I'll put comments in later...