changed function to determine correct tree type