Basic tree view works now. Tidying up other functions.