Refactor to simplify (return nil for invalid tree)