Fix max and copy of w