Fixed a bug with counting max times