Fixed "isTree" function