Fix unit tests
Test and really fix tree sorting