improve error handling when tree is empty