Refactored javascript so that treeview is all in one function + bug in treeview - styles not being applied correctly.