changed max counting method