added function to count alive objects