Make gentree() global