fixed bug with counting max value