implemented max for tree