fix the max and restore window function