code to produce trees