add counting messages function