Tidying up tree code.