fixing 'undefined' count vars