Moved tree code to own source file.