Fix max value calculation for stack