Cleaned up tree code.